var cons = require('consolidate');
var isWebsite = false;
var promise = require('bluebird');
var utils = promise
    .promisifyAll(require('/Users/Steve/tools/myGit/xNode/common/FooUtils.js'));

var token;
if (process.argv[2]) {
    token = process.argv[2].trim();
} else {
    // unit test only.
    token = "tenmalife-platform";
}

if (token == 'enjoy-website') {
    isWebsite = true;
} else {
    isWebsite = false;
}

var tmplFile = __dirname + '/AWF-TomcatHelperAction.xml';

var tomcatRootFilePath = utils.readJson("/Users/Steve/tools/myGit/xNode/global-config.json", (err, data)=> {
    tomcatRootFilePath = data.tomcatRootFilePath;
});

utils.renderWithMustacheAsync(tmplFile, {
    "isWebsite": isWebsite,
    "artifact": token
}).then(function (res) {
    return utils.writeFileAsync(tomcatRootFilePath, res);
}).then(function (res) {
    console.log('config artifact of:%s success.', token);
}).catch(function (err) {
    console.log(`config artifact of:${token} error of:${err}`);
});

